home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0142_Gravity in Graphics.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  987b  |  36 lines

  1. {
  2. > ex. pixel in screen is x = 160, y = 100 and ground level = 190.
  3. > Then that pixel has to drop down like a gravity affect to
  4. > pixel.. then it would look that there were an gravity..
  5. }
  6.  
  7. program cannonball;
  8. uses crt;
  9. const vidseg:word=$a000; g=-9.81; x0=0; y0=100; v0=50; phi=50; dt=0.1;
  10. var t:real; px,py,xt,yt,v:integer;
  11.  
  12. procedure retrace; assembler; asm
  13.   mov dx,03dah; @vert1: in al,dx; test al,8; jnz @vert1
  14.   @vert2: in al,dx; test al,8; jz @vert2; end;
  15.  
  16. function rad(alpha:integer):real; begin
  17.   rad:=(alpha/180)*pi; end;
  18.  
  19. begin
  20.   asm mov ax,13h; int 10h; end;
  21.   px:=0; py:=0;
  22.   t:=0; v:=v0; yt:=1;
  23.   while (not keypressed) and (yt>=0) do begin
  24.     retrace;
  25.     mem[vidseg:(199-py)*320+px]:=0;
  26.     xt:=x0+round(v0*cos(rad(phi))*t);
  27.     yt:=y0+round(v*sin(rad(phi))*t+0.5*g*t*t);
  28.     mem[vidseg:(199-yt)*320+xt]:=15;
  29.     px:=xt; py:=yt;
  30.     t:=t+dt;
  31.   end;
  32.   while keypressed do readkey;
  33.   while not keypressed do;
  34.   textmode(lastmode);
  35. end.
  36.